#include "main.h"
#include "FLASH.h"

void Flash_Write(uint32_t n)
{
	HAL_FLASH_Unlock();
	EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
	EraseInitStruct.PageAddress = 0x0801FC00;
	EraseInitStruct.NbPages = 1;
	uint32_t PageError = 0;
	HAL_FLASHEx_Erase(&EraseInitStruct,&PageError);
//	if(HAL_FLASHEx_Erase(&EraseInitStruct,&PageError) == HAL_OK)
//	{
//		printf("擦除成功\r\n");
//	}
//	else
//	{
//		printf("擦除失败\r\n");
//	}
	uint32_t writeFlashData = n;
	uint32_t addr = 0x0801FC00;
	HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD,addr,writeFlashData);
	HAL_FLASH_Lock();
}

uint32_t FLASH_READ()
{
	HAL_FLASH_Unlock();
	uint32_t Page = 0;
	uint32_t addr = 0x0801FC00;
	Page = *(__IO uint32_t*)addr;
	HAL_FLASH_Lock();
	return Page;
}